package com.sdyd.antivirus.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author liujia
 * @date 2020/2/1 19:51
 **/
public class DateUtil {
    /**
     * 获取前一天日期
     * @return
     */
    public static String getYesterdayDate(){

        DateFormat dateFormat=new SimpleDateFormat("yyyyMMdd");
        Calendar calendar=Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY,-24);
       return dateFormat.format(calendar.getTime());

    }

    public static String getTodayDate(){
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
       return formatter.format(date);
    }


    public static String getNextDate(String date){
        String nextDay=null;
        DateFormat dft = new SimpleDateFormat("yyyyMMdd");
        try {
            Date temp = dft.parse(date);
            Calendar cld = Calendar.getInstance();
            cld.setTime(temp);
            cld.add(Calendar.DATE, 1);
            temp = cld.getTime();
            //获得下一天日期字符串
             nextDay = dft.format(temp);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return nextDay;
    }
    public static void main(String[] args) {
        System.out.println(getNextDate("20200209"));
    }
}
